﻿Public NotInheritable Class frmGraphics
    Private m_intGraphicIndex As Integer
    Private m_objMyGraphics As MyGraphics
    Private m_objGraphPane As ZedGraph.GraphPane

    Private Enum AxisConstants
        X_Y
        X_LogY
        LogX_Y
        LogX_LogY
    End Enum

    Public Sub New(ByVal graphics As MyGraphics)
        ' This call is required by the Windows Form Designer.
        Me.InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        m_objMyGraphics = graphics
        m_objGraphPane = Me.ZedGraphControl1.GraphPane
        Me.Translate()
        Me.PrepareGraphics()
    End Sub


    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        If m_intGraphicIndex > 0 Then
            m_intGraphicIndex -= 1
            Me.LoadGraphic()
        End If        
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        If m_intGraphicIndex < m_objMyGraphics.Count - 1 Then
            m_intGraphicIndex += 1
            Me.LoadGraphic()
        End If
    End Sub

    Private Sub ToolStripComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripComboBox1.SelectedIndexChanged
        Me.LoadGraphic()
    End Sub


    Private Sub LoadGraphic()
        Dim objGraphic As MyGraphics.Graphic = m_objMyGraphics.Item(m_intGraphicIndex)        

        Me.ToolStripLabel1.Text = (m_intGraphicIndex + 1).ToString + " / " + m_objMyGraphics.Count.ToString

        m_objGraphPane.CurveList.Clear()
        m_objGraphPane.Title.Text = objGraphic.Title
        m_objGraphPane.XAxis.Title.Text = objGraphic.XAxisLabel
        m_objGraphPane.YAxis.Title.Text = objGraphic.YAxisLabel
        Select Case CType(Me.ToolStripComboBox1.SelectedIndex, AxisConstants)
            Case AxisConstants.X_Y
                m_objGraphPane.XAxis.Type = ZedGraph.AxisType.Linear
                m_objGraphPane.YAxis.Type = ZedGraph.AxisType.Linear

            Case AxisConstants.X_LogY
                m_objGraphPane.XAxis.Type = ZedGraph.AxisType.Linear
                m_objGraphPane.YAxis.Type = ZedGraph.AxisType.Log
                m_objGraphPane.YAxis.Title.Text += " [" + Language.ReadMessages("msgLOG") + "]"

            Case AxisConstants.LogX_Y
                m_objGraphPane.XAxis.Type = ZedGraph.AxisType.Log
                m_objGraphPane.YAxis.Type = ZedGraph.AxisType.Linear
                m_objGraphPane.XAxis.Title.Text += " [" + Language.ReadMessages("msgLOG") + "]"

            Case AxisConstants.LogX_LogY
                m_objGraphPane.XAxis.Type = ZedGraph.AxisType.Log
                m_objGraphPane.YAxis.Type = ZedGraph.AxisType.Log
                m_objGraphPane.XAxis.Title.Text += " [" + Language.ReadMessages("msgLOG") + "]"
                m_objGraphPane.YAxis.Title.Text += " [" + Language.ReadMessages("msgLOG") + "]"
        End Select

        For intIndex As Integer = 0 To objGraphic.Count - 1
            Dim objCurve As MyGraphics.Graphic.Curve = objGraphic.Item(intIndex)
            Dim objLineItem As ZedGraph.LineItem = m_objGraphPane.AddCurve(objCurve.Label, objCurve.Xdata, objCurve.Ydata, objCurve.Color, ZedGraph.SymbolType.None)

            With objLineItem.Line
                .IsAntiAlias = True
                .IsOptimizedDraw = True
                .IsSmooth = True
                .Width = 2
            End With
        Next

        Me.ZedGraphControl1.RestoreScale(m_objGraphPane)
        Me.ZedGraphControl1.Refresh()
    End Sub

    Private Sub PrepareGraphics()
        m_objGraphPane.Title.FontSpec.Size = 10
        m_objGraphPane.XAxis.Title.FontSpec.Size = 8
        m_objGraphPane.XAxis.Scale.FontSpec.Size = 8
        m_objGraphPane.YAxis.Title.FontSpec.Size = 8
        m_objGraphPane.YAxis.Scale.FontSpec.Size = 8
        m_objGraphPane.Legend.FontSpec.Size = 8

        With Me.ToolStripComboBox1.Items
            .Add(Language.ReadMessages("msgAXIS_0"))
            .Add(Language.ReadMessages("msgAXIS_1"))
            .Add(Language.ReadMessages("msgAXIS_2"))
            .Add(Language.ReadMessages("msgAXIS_3"))
        End With
        Me.ToolStripComboBox1.SelectedIndex = 0
    End Sub

    Private Sub Translate()
        Me.ToolStripLabel2.Text = Language.ReadMessages("msgAXIS") + ":"
    End Sub

End Class